package com.example.demo.base;

import java.io.Serializable;
import java.util.*;

public class MyFactoryArrayList<E extends MatchingBean<K>, K> extends ArrayList<E>
        implements MyFactoryList<E, K>, Serializable {

    @Override
    public E getBean(K factor) {
        for (E beanMatch : this) {
            if (beanMatch.matching(factor)) {
                return beanMatch;
            }
        }
        return null;
    }

    @Override
    public List<E> getBeanList(K factor) {
        removeIf(beanMatch -> !beanMatch.matching(factor));
        return this;
    }

}
